from django.shortcuts import render
from apps.message_form.models import Message


# Create your views here.


def message_from(request):
    name = request.POST.get('name', '')
    email = request.POST.get('email', '')
    address = request.POST.get('address', '')
    message_text = request.POST.get('message', '')
    print(name, email, address, message_text)
    if request.method == 'POST':
        message = Message()
        message.name = name
        message.email = email
        message.address = address
        message.message = message_text
        message.save()

    if request.method == 'GET':
        var_dict = {}
        all_message = Message.objects.all()
        if all_message:
            message = all_message[0]
            var_dict = {'message': message}
        return render(request, 'message_form.html', locals())
    return render(request, 'message_form.html', locals())